﻿using System.Linq;
using RealEstate.Models;
using System.Collections.Generic;
namespace RealEstate
{
    public partial class ClientTypeEntities
    {
        private DataClassesDataContext dataContext = new DataClassesDataContext();

        public void Add(ClientType item)
        {
            dataContext.ClientTypes.InsertOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public void Update(ClientType item)
        {
            var updateItem = (from c in dataContext.ClientTypes where c.Id == item.Id select c).FirstOrDefault();
            dataContext.SubmitChanges();
        }

        public void Delete(int id)
        {
            var item = (from c in dataContext.ClientTypes where c.Id == id select c).FirstOrDefault();            
            dataContext.ClientTypes.DeleteOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public ClientType GetById(int id)
        {
            var item = (from c in dataContext.ClientTypes where c.Id == id select c).FirstOrDefault();
            return item;
        }

        public List<ClientType> GetAll()
        {
            return dataContext.ClientTypes.OrderBy(c => c.Id).ToList();
        }
    }
}